app.controller("bookController",['$scope','$http','myPage', function($scope, $http, myPage){
        $scope.myPage={
            currentPage:1,//访问第几页数据，从1开始
            totalItems:0,//数据库中总共有多少条数据
            itemsPerPage: 6,//默认每页展示多少条数据，可更改
            pagesLength: 15,
            perPageOptions: [10, 20, 30, 40, 50,60]//可选择的每页展示多少条数据
        };
        //监测当页码。总数据，每页展示数据个数变化时，重新加载数据
        $scope.$watch(function ()
        {return $scope.myPage.itemsPerPage+' '+$scope.myPage.currentPage+' '+$scope.myPage.totalItems;},getList) ;
        function getList(){
            //获取列表需要时，将页码重置为1
            $scope.myPage.currentPage=myPage.pageNub;
            //传给服务器时，页码从0开始
            // 定义查询按钮
            var listJson={};
            function changeJson(){
                var username=$("#username").val();
                return {pageNumber:myPage.pageNub,username:username}
            }
            listJson=changeJson();
            $scope.find=function () {
                listJson=changeJson();
                Json()
            }
            Json();
            // 获取列表接口
            function  Json() {
                $http({
                    method: 'POST',
                    url: '/OA/staff/list',
                    data: $.param(listJson),
                    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                }).success(function (response) {
                    console.log(response.data)
                    $scope.datas=response.data.list;
                    $scope.pageSize=response.data.pageSize;
                    $scope.pageNumber=response.data.pageNumber;
                    $scope.myPage.totalItems=response.data.totalRow;//当获取总数据后，修改默认值;
                    // 定义一个空对象 , 用于更新和保存数据时临时存储
                    $scope.prod = {};
                    $scope.arrs=$scope.datas;
                })
            }
        }

        $scope.change = function(selectedLimit){
            $scope.page.limit = selectedLimit.limit;
        }
        $scope.pageChanged = function(){
            $scope.page.limit = $scope.selectedLimit.limit;
        }
        $scope.setPage = function (go) {
            $scope.length = Math.ceil($scope.total/$scope.selectedLimit.limit);
            console.log($scope.length);
            if(go > $scope.length){
                $scope.page.pageNo =  $scope.length;
                console.log($scope.length);
            }else{
                $scope.page.pageNo=go;
            }
        };
    }]);



